%%% @author LinZhengJian <linzhj@35info.cn>
%%% @copyright (C) 2012, LinZhengJian
%%% @doc
%%%
%%% @end
%%% Created : 15 Aug 2012 by LinZhengJian <linzhj@35info.cn>

-module(heyjude_database_utility).

-include("heyjude_database.hrl").

-export([is_table_exists/1]).

-export([is_ran_script/1, log_ran_script/1]).

is_table_exists(Table)->
    lists:member(Table, mnesia:table_info(schema, tables)).


is_ran_script(Id)->
    case mnesia:dirty_read(?SYS_TABLE_SCRIPT_LOG, Id) of
	[#?SYS_TABLE_SCRIPT_LOG{}]->
	    true;
	_Other ->
	    false
    end.

log_ran_script(Id)->
    mnesia:dirty_write(#?SYS_TABLE_SCRIPT_LOG{id=Id, createat=calendar:local_time()}).
